package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import com.atguigu.gmall.product.service.SpuInfoService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.security.PermitAll;
import java.util.List;
@Api(value = "后台获取商品标签")
@RequestMapping("/admin/product")
@RestController
public class ManageController {
    @Autowired
    private ManageService Service;

    @Autowired
    private SpuInfoService spuInfoService;

    @ApiOperation(value = "获取spu分页列表")
    @GetMapping("/{page}/{limit}")
    public Result getSpuPage(@ApiParam("当前页")@PathVariable Integer page,
                             @ApiParam("展现条数")@PathVariable Integer limit,
                             @ApiParam("三级分类ID")@RequestParam String category3Id){
        IPage iPage=spuInfoService.getSpuPage(page,limit,category3Id);
        return Result.ok(iPage);
    }

    @ApiOperation(value = "获取Spu品牌信息")
    @GetMapping("/baseTrademark/getTrademarkList")
    public Result getTrademarkList(){
        List<BaseTrademark> list=spuInfoService.getTrademarkList();
        return Result.ok(list);
    }

    @ApiOperation(value = "获取一级标签")
    @GetMapping("/getCategory1")
    public Result getCategory1(){
        List<BaseCategory1> baseCategory1List=Service.getCategory1();
    return Result.ok(baseCategory1List);
    }

    @ApiOperation(value = "获取二级标签")
    @GetMapping("/getCategory2/{category1Id}")
    public Result getCategory2(@ApiParam(value = "一级id")@PathVariable Long category1Id){
        List<BaseCategory2> list=Service.getCategoty2(category1Id);
        return Result.ok(list);
    }

    @ApiOperation(value = "获取三级标签")
    @GetMapping("/getCategory3/{category2Id}")
    public Result getCategory3(@ApiParam(value = "二级id")@PathVariable Long category2Id){
        List<BaseCategory3> list=Service.getCategory3(category2Id);
        return Result.ok(list);
    }

    @ApiOperation(value = "根据分类id获取平台属性")
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@ApiParam(value = "一级id") @PathVariable Long category1Id,
                               @ApiParam(value = "二级id") @PathVariable Long category2Id,
                               @ApiParam(value = "三级id") @PathVariable Long category3Id){
        List<BaseAttrInfo> list=Service.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(list);
    }

    @ApiOperation(value = "添加平台属性")
    @PostMapping("/saveAttrInfo")
    public Result saveAttrInfo(@ApiParam("平台属性")@RequestBody BaseAttrInfo baseAttrInfo){
        Service.saveAttrInfo(baseAttrInfo);
        return Result.ok();
    }

    @ApiOperation(value = "修改回显平台属性")
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@ApiParam("平台属性id")@PathVariable Long attrId){
        List<BaseAttrValue> baseAttrValue=Service.getAttrValueList(attrId);
        return Result.ok(baseAttrValue);
    }

    @ApiOperation(value = "获取品牌列表")
    @GetMapping("/baseTrademark/{page}/{limit}")
    public Result baseTrademark(@PathVariable Integer page,@PathVariable Integer limit){
        IPage iPage=Service.baseTrademark(page,limit);
        return Result.ok(iPage);
    }

    @ApiOperation(value = "删除品牌列表")
    @DeleteMapping("/baseTrademark/remove/{id}")
    public Result baseTrademarkRemove(@PathVariable Long id){
        Service.baseTrademarkRemove(id);
        return Result.ok();
    }

    @ApiOperation(value = "修改品牌列表回显")
    @GetMapping("baseTrademark/get/{id}")
    public Result baseTrademarkGet(@PathVariable Long id){
        BaseTrademark baseTrademark=Service.baseTrademarkGet(id);
        return Result.ok(baseTrademark);
    }

    @ApiOperation(value = "修改品牌列表")
    @PutMapping("baseTrademark/update")
    public Result baseTrademarkUpdate(@RequestBody BaseTrademark baseTrademark){
        Service.baseTrademarkUpdate(baseTrademark);
        return Result.ok();
    }

    @ApiOperation(value = "添加品牌列表")
    @PostMapping("/baseTrademark/save")
    public Result baseTrademarkSave(@RequestBody BaseTrademark baseTrademark){
        Service.baseTrademarkSave(baseTrademark);
        return Result.ok();
    }

    @ApiOperation(value = "SPU获取销售属性")
    @GetMapping("/baseSaleAttrList")
    public Result baseSaleAttrList(){
        List<BaseSaleAttr> list=Service.baseSaleAttrList();
        return Result.ok(list);
    }

    @ApiOperation(value = "获取SKU列表")
    @GetMapping("/list/{page}/{limit}")
    public Result SKUList(@PathVariable Integer page,@PathVariable Integer limit){
        IPage iPage=Service.SKUList(page,limit);
        return Result.ok(iPage);
    }

    @ApiOperation(value = "获取Spu属性")
    @GetMapping("/spuSaleAttrList/{id}")
    public Result spuSaleAttrList(@PathVariable Long id){
        List<SpuSaleAttr> list=Service.spuSaleAttrList(id);
        return Result.ok(list);
    }

    @ApiOperation(value = "获取SKU图片")
    @GetMapping("/spuImageList/{spuId}")
    public Result spuImageList(@PathVariable Long spuId){
        List<SpuImage> list=Service.spuImageList(spuId);
        return Result.ok(list);
    }

    @ApiOperation(value = "上架")
    @GetMapping("/onSale/{id}")
    public Result onSale(@PathVariable Long id){
        Service.onSale(id);
        return Result.ok();
    }

    @ApiOperation(value = "下架")
    @GetMapping("/cancelSale/{id}")
    public Result cancelSale(@PathVariable Long id){
        Service.cancelSale(id);
        return Result.ok();
    }

    @ApiOperation(value = "添加SPU")
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo){
        Service.saveSpuInfo(spuInfo);
        return Result.ok();
    }


    @ApiOperation(value = "添加SKU")
    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        Service.saveSkuInfo(skuInfo);
        return Result.ok();
    }
}
